using Godot;
using System;
namespace Views.Edit
{
    public class EditViewport : Control
    {
        #region Fields

        [Export]
        private StyleBox _bgStyle;

        [Export]
        private Color _canvasLineColor = ColorUtil.FromHSV(260, 1, 1, 0.45f);

        [Export]
        private Texture _canvasTexture;

        [Export]
        private Font _infoFont;

        private EditCanvas _canvas;
        private EditView _view;
        private EditViewportInteractive _interactive;

        #endregion

        #region Propertys
        public EditView EditView
        {
            get
            {
                if (_view == null)
                    _view = GetParent<EditView>();
                return _view;
            }
        }
        public EditCanvas EditCanvas
        {
            get
            {
                if (_canvas == null)
                    _canvas = GetNode<EditCanvas>("Canvas");
                return _canvas;
            }
        }
        public EditViewportInteractive Interactive
        {
            get
            {
                if (_interactive == null)
                    _interactive = GetNode<EditViewportInteractive>("Interactive");
                return _interactive;
            }
        }

        #endregion

        #region Godot API
        
        public override void _Ready()
        {
            if (_infoFont == null)
                _infoFont = GetThemeDefaultFont();
        }

        public override void _Draw()
        {
            DrawCanvasBg();
        }

        #endregion
        
        #region Private Function
        private void DrawCanvasBg()
        {
            var rect = EditCanvas.Rect;
            rect.Position -= Vector2.One;
            rect.Size += Vector2.One * 2;
            //DrawStyleBox(_bgStyle, rect);
            DrawTextureRect(_canvasTexture, rect, true);
            DrawRect(rect, _canvasLineColor, false);
        }

        #endregion
    }
}

